package jwdt.xadmin.work.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.system.bean.TUser;
import jwdt.xadmin.work.bean.TTask;
import jwdt.xadmin.work.service.TaskManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/work")
public class TaskManagerAction extends BaseAction {

	private TaskManageService taskManageService = (TaskManageService)app.getBean("taskManageService");
	
	@RequestMapping("/listTask")
	public Page doListTask(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TUser userInfo = (TUser) f.getSession("userInfo");
		int projectId = f.getInt("projectId");
		int flag = f.getInt("flag");
    	return m.getWritePage(f, taskManageService.doList(pu,projectId,flag,userInfo).toJson());
	}
	
	@RequestMapping("/addTask")
	public Page doAddact(Form f, Module m) throws Exception {
		TTask obj = (TTask)f.copy2Class(TTask.class);
		TUser userInfo = (TUser) f.getSession("userInfo");
		return m.getWritePage(f, taskManageService.doAddact(obj,userInfo));
	}
	
	@RequestMapping("/editTask")
	public Page doEditact(Form f, Module m) throws Exception {
		int taskid = f.getInt("taskid");
		TTask obj = (TTask)f.copy2Class(TTask.class);
		return m.getWritePage(f, taskManageService.doEditact(obj, taskid));
	}
	
	@RequestMapping("/delTask")
	public Page doDel(Form f, Module m) throws Exception {
		int projectid = f.getInt("taskid");
		return m.getWritePage(f, taskManageService.doDelact(projectid));
	}
	
	@RequestMapping("/taskWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int taskid = f.getInt("taskid");
		f.add("obj", taskManageService.doLoad(taskid));
		return m.findPage("/xadmin/work/taskWindow");
	}
	
	@RequestMapping("/updateTaskState")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int taskid = f.getInt("taskid");
		String result = f.getString("result");
		return m.getWritePage(f, taskManageService.doUpdateState(taskid,result));
	}
	
	@RequestMapping("/mytaskManage")
	public Page doMytaskManage(Form f, Module m) throws Exception {
		return m.findPage("/xadmin/work/mytaskManage");
	}
}
